package controller;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;   
/**
 * Servlet implementation class PrintWriter
 */
@WebServlet("/CDFServlet")
public class CDFServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CDFServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	  // 导入 OutputStream 类
    
	// public class ABCServlet extends HttpServlet {... ...
	    
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	        // 设置请求编码格式
	        request.setCharacterEncoding("UTF-8");
	        // 设置响应编码格式
	        response.setContentType("image/jpeg");
	        // 获取响应输出流
	        OutputStream out = response.getOutputStream();
	        // 生成二进制数据
	        byte[] data = new byte[1024];
	        out.write(data);
	        out.write(65);
	        out.flush();
	        out.close();
	}

}
